package com.dxysun.controller;

import com.dxysun.annotation.DXYAutowired;
import com.dxysun.annotation.DXYController;
import com.dxysun.annotation.DXYRequestMapping;
import com.dxysun.annotation.DXYRequestParam;
import com.dxysun.spring.mvc.DXYModelAndView;
import com.dxysun.service.api.HelloService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@DXYController
@DXYRequestMapping("/dxy")
public class HelloController
{
	@DXYAutowired
	private HelloService helloService;

	@DXYRequestMapping("/hello")
	public void hello(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
			@DXYRequestParam("name") String name)
	{
		String str = helloService.sayHello(name);
		try
		{
			httpServletResponse.getWriter().write(str);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	@DXYRequestMapping("/abc")
	public void abc(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
			@DXYRequestParam("code") String name)
	{
		String str = helloService.sayHello(name);
		try
		{
			httpServletResponse.getWriter().write(str);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	@DXYRequestMapping("/first.html")
	public DXYModelAndView query(@DXYRequestParam("teacher") String teacher)
	{
		String result = helloService.sayHello(teacher);
		Map<String, Object> model = new HashMap<>();
		model.put("teacher", teacher);
		model.put("data", result);
		model.put("token", "123456");
		return new DXYModelAndView("first.html", model);
	}
}
